#include <iostream>
#include <vector>
#include <fstream>
#include "Spline.hpp"
#include "Function.hpp"

void testBSpline(const std::vector<double>& knots, const std::vector<double>& coefficients, int degree, const std::string& filename) {
    double interval = knots[1] - knots[0];
    std::vector<double> exknots = {knots.front() - interval};
    for (int i = 0; i < knots.size(); ++i) {
        exknots.push_back(knots[i]);
    }
    for (int i = 1; i <= degree; ++i) {
        exknots.push_back(knots.back() + i * interval);
    }
    BSpline spline(exknots, degree, coefficients);
    std::ofstream outfile("output/T5_" + filename + ".txt");
    for (double x = exknots.front(); x <= exknots.back(); x += 0.01) {
        double y = spline.evaluate(x);
        outfile << x << " " << y << std::endl;
    }
    outfile.close();
}

int main() {
    // Define knots and coefficients
    std::vector<double> knots = {0, 0.8, 2.3, 3, 4, 5, 6, 7, 8.7, 9, 10};
    std::vector<double> coefficients = {0.7, 1, -2, 3, -0.6, -3.8, 0, 3, 2, -1, -0.3};

    // Test degree 2 B-spline
    testBSpline(knots, coefficients, 2, "Degree2");

    // Test degree 4 B-spline
    testBSpline(knots, coefficients, 4, "Degree4");

    // Test degree 5 B-spline
    testBSpline(knots, coefficients, 5, "Degree5");

    // Test degree 6 B-spline
    testBSpline(knots, coefficients, 6, "Degree6");

    // Test degree 7 B-spline
    testBSpline(knots, coefficients, 7, "Degree7");
    return 0;
}
